Skip to content

fix(ai): preserve numeric status field in RUN_ERROR payloads - #985

Merged
AlemTuzlak merged 2 commits into
TanStack:mainfrom
jan-kubica:fix/run-error-preserve-numeric-status
Aug 10, 2026
Merged

fix(ai): preserve numeric status field in RUN_ERROR payloads#985
AlemTuzlak merged 2 commits into
TanStack:mainfrom
jan-kubica:fix/run-error-preserve-numeric-status

Conversation

@jan-kubica

@jan-kubica jan-kubica commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

toRunErrorPayload dropped the HTTP status for SDK error classes that report it only as a numeric status field with no code (e.g. Google's @google/genai ApiError), leaving RUN_ERROR events with code: undefined and making 401/403/404/429 indistinguishable from unknown failures. Fall back to a numeric status when no code is present; ignore a string status (reason phrase / symbolic status) so only the numeric HTTP code is forwarded.

🎯 Changes

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Error payloads now preserve numeric status codes when an explicit error code is unavailable.
    • Explicit error codes continue to take precedence.
    • String-based statuses are ignored to prevent invalid error codes.
    • Improved handling of API errors with JSON-formatted messages.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 02943f5c-22ec-4c0c-b15a-a93162e96d34

📥 Commits

Reviewing files that changed from the base of the PR and between 888e8b7 and 61497f1.

📒 Files selected for processing (3)
  • .changeset/run-error-numeric-status.md
  • packages/ai/src/activities/error-payload.ts
  • packages/ai/tests/error-payload.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/ai/src/activities/error-payload.ts
  • packages/ai/tests/error-payload.test.ts
  • .changeset/run-error-numeric-status.md

📝 Walkthrough

Walkthrough

toRunErrorPayload now uses numeric status values as fallback error codes when code is absent. Explicit codes remain preferred, string statuses remain ignored, and provider messages remain unchanged.

Changes

Error payload status handling

Layer / File(s) Summary
Extract and wire numeric error codes
packages/ai/src/activities/error-payload.ts
Adds extractCode and uses it for Error instances and generic objects. Numeric status values provide fallback codes, while explicit code values take precedence.
Validate and document fallback behavior
packages/ai/tests/error-payload.test.ts, .changeset/run-error-numeric-status.md
Tests cover numeric statuses, explicit code precedence, ignored string statuses, and @google/genai messages. The changeset documents the patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: preserving numeric status values in RUN_ERROR payloads.
Description check ✅ Passed The description explains the issue and solution, includes the required headings, and marks the checklist and release impact accurately.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@jan-kubica
jan-kubica marked this pull request as ready for review August 7, 2026 16:09
toRunErrorPayload dropped the HTTP status for SDK error classes that report
it only as a numeric `status` field with no `code` (e.g. Google's
@google/genai ApiError), leaving RUN_ERROR events with code: undefined and
making 401/403/404/429 indistinguishable from unknown failures. Fall back to
a numeric `status` when no `code` is present; ignore a string `status`
(reason phrase / symbolic status) so only the numeric HTTP code is forwarded.
@tombeckenham
tombeckenham force-pushed the fix/run-error-preserve-numeric-status branch from b55ce89 to 1ae5052 Compare August 10, 2026 09:09
@tombeckenham

Copy link
Copy Markdown
Contributor

Maintainer sweep: rebased onto main (force-with-lease). CI approval handled if it was waiting.

@nx-cloud

nx-cloud Bot commented Aug 10, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 61497f1

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 8m 55s View ↗
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 1m 51s View ↗

☁️ Nx Cloud last updated this comment at 2026-08-10 11:36:25 UTC

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@pkg-pr-new

pkg-pr-new Bot commented Aug 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/@tanstack/ai@985

@tanstack/ai-acp

npm i https://pkg.pr.new/@tanstack/ai-acp@985

@tanstack/ai-angular

npm i https://pkg.pr.new/@tanstack/ai-angular@985

@tanstack/ai-anthropic

npm i https://pkg.pr.new/@tanstack/ai-anthropic@985

@tanstack/ai-bedrock

npm i https://pkg.pr.new/@tanstack/ai-bedrock@985

@tanstack/ai-byteplus

npm i https://pkg.pr.new/@tanstack/ai-byteplus@985

@tanstack/ai-claude-code

npm i https://pkg.pr.new/@tanstack/ai-claude-code@985

@tanstack/ai-client

npm i https://pkg.pr.new/@tanstack/ai-client@985

@tanstack/ai-code-mode

npm i https://pkg.pr.new/@tanstack/ai-code-mode@985

@tanstack/ai-code-mode-skills

npm i https://pkg.pr.new/@tanstack/ai-code-mode-skills@985

@tanstack/ai-codex

npm i https://pkg.pr.new/@tanstack/ai-codex@985

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/@tanstack/ai-devtools-core@985

@tanstack/ai-durable-stream

npm i https://pkg.pr.new/@tanstack/ai-durable-stream@985

@tanstack/ai-elevenlabs

npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@985

@tanstack/ai-event-client

npm i https://pkg.pr.new/@tanstack/ai-event-client@985

@tanstack/ai-fal

npm i https://pkg.pr.new/@tanstack/ai-fal@985

@tanstack/ai-gemini

npm i https://pkg.pr.new/@tanstack/ai-gemini@985

@tanstack/ai-grok

npm i https://pkg.pr.new/@tanstack/ai-grok@985

@tanstack/ai-grok-build

npm i https://pkg.pr.new/@tanstack/ai-grok-build@985

@tanstack/ai-groq

npm i https://pkg.pr.new/@tanstack/ai-groq@985

@tanstack/ai-isolate-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@985

@tanstack/ai-isolate-daytona

npm i https://pkg.pr.new/@tanstack/ai-isolate-daytona@985

@tanstack/ai-isolate-node

npm i https://pkg.pr.new/@tanstack/ai-isolate-node@985

@tanstack/ai-isolate-quickjs

npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@985

@tanstack/ai-isolate-quickjs-bun

npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs-bun@985

@tanstack/ai-mcp

npm i https://pkg.pr.new/@tanstack/ai-mcp@985

@tanstack/ai-memory

npm i https://pkg.pr.new/@tanstack/ai-memory@985

@tanstack/ai-mistral

npm i https://pkg.pr.new/@tanstack/ai-mistral@985

@tanstack/ai-ollama

npm i https://pkg.pr.new/@tanstack/ai-ollama@985

@tanstack/ai-openai

npm i https://pkg.pr.new/@tanstack/ai-openai@985

@tanstack/ai-opencode

npm i https://pkg.pr.new/@tanstack/ai-opencode@985

@tanstack/ai-openrouter

npm i https://pkg.pr.new/@tanstack/ai-openrouter@985

@tanstack/ai-persistence

npm i https://pkg.pr.new/@tanstack/ai-persistence@985

@tanstack/ai-preact

npm i https://pkg.pr.new/@tanstack/ai-preact@985

@tanstack/ai-react

npm i https://pkg.pr.new/@tanstack/ai-react@985

@tanstack/ai-react-ui

npm i https://pkg.pr.new/@tanstack/ai-react-ui@985

@tanstack/ai-sandbox

npm i https://pkg.pr.new/@tanstack/ai-sandbox@985

@tanstack/ai-sandbox-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-sandbox-cloudflare@985

@tanstack/ai-sandbox-daytona

npm i https://pkg.pr.new/@tanstack/ai-sandbox-daytona@985

@tanstack/ai-sandbox-docker

npm i https://pkg.pr.new/@tanstack/ai-sandbox-docker@985

@tanstack/ai-sandbox-local-process

npm i https://pkg.pr.new/@tanstack/ai-sandbox-local-process@985

@tanstack/ai-sandbox-sprites

npm i https://pkg.pr.new/@tanstack/ai-sandbox-sprites@985

@tanstack/ai-sandbox-vercel

npm i https://pkg.pr.new/@tanstack/ai-sandbox-vercel@985

@tanstack/ai-solid

npm i https://pkg.pr.new/@tanstack/ai-solid@985

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/@tanstack/ai-solid-ui@985

@tanstack/ai-svelte

npm i https://pkg.pr.new/@tanstack/ai-svelte@985

@tanstack/ai-utils

npm i https://pkg.pr.new/@tanstack/ai-utils@985

@tanstack/ai-vue

npm i https://pkg.pr.new/@tanstack/ai-vue@985

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/@tanstack/ai-vue-ui@985

@tanstack/openai-base

npm i https://pkg.pr.new/@tanstack/openai-base@985

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@985

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/@tanstack/react-ai-devtools@985

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@985

commit: 61497f1

@AlemTuzlak
AlemTuzlak merged commit fdb791a into TanStack:main Aug 10, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants